import Vue from 'vue'
import App from './App.vue'

Vue.config.productionTip = false

import VueRouter from 'vue-router'
Vue.use(VueRouter)
import Liucong from './views/Liucong.vue'
import DaSha from './views/DaSha.vue'
import GongFuPang from './views/GongfuPang.vue'
import _404 from './views/404.vue'

import Jianghuliu from './views/Jianghuliu.vue'
import Live from './views/Live.vue'
import HeyKong from './views/HeyKong.vue'

const routes = [
  {
    path : '/',
    redirect: 'dasha'    //强制跳转
  },
  {
    path : '/liucong',
    component : Liucong,
    redirect : '/liucong/live',
    children : [
      {
        path : 'heykong',
        component : HeyKong,
      },
      {
        path : 'live',
        component : Live,
      },
      {
        path : 'jianghuliu',
        component : Jianghuliu
      }
    ]
  },
  {
    path : '/dasha',
    component : DaSha
  },
  {
    path : '/gongfupang',
    component : GongFuPang
  },
  {
    path : '*',
    component : _404
  }
]

const router = new VueRouter({
  routes,
  linkActiveClass : 'on1',
  linkExactActiveClass : 'on2',
  mode : 'history'
})

// 路由的全局前置守卫
// let isLogin = false
// router.beforeEach((to,from,next) => {
//   console.log(to);      //要去哪
//   // console.log(from);    //从哪来
//   // console.log(next);    //函数，决定是否跳转
//   if (to.path === '/liucong/heykong' && isLogin === false) {
//     alert('请先登录')
//     next(false)  //停留在原地(不生跳转)
//   } else {
//     next()   //正常放行
//   }
// })

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')
